package com.lnj.messages.servise;

import com.lnj.messages.utiles.JsonUtil;
import com.lnj.utils.OrderMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
public class NotificationService {
    @Autowired
    private KafkaTemplate kafkaTemplate;
    @Autowired
    private JsonUtil jsonUtil;

    //发送支付提醒
    public void sendPaymentRemind(Long orderId) {
        // 发送支付提醒消息
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setOrderId(orderId);
        orderMessage.setEventType("REMINDED");
        kafkaTemplate.send("orders.reminded", jsonUtil.toJson(orderMessage));
    }

    //发送订单取消提醒
    public void sendOrderCancelled(Long orderId) {
        // 发送订单取消消息
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setOrderId(orderId);
        orderMessage.setEventType("CANCELLED");
        kafkaTemplate.send("orders.cancelled", jsonUtil.toJson(orderMessage));
    }
}
